package ru.beta2.testyard.engine;

import ru.beta2.testyard.Step;

/**
 * User: Inc
 * Date: 19.06.2008
 * Time: 19:42:49
 */
public abstract class AbstractStep extends AbstractScript implements Step
{

    protected String stepName = "1st";
    protected StepNode next;

    protected int index = 1;

    public Step nextStep()
    {
        return nextStep(null);
    }

    public Step nextStep(String name)
    {
        if (next == null) {
            next = new StepNode(getContext());
            next.index = ++index;

            if (name != null) {
                next.stepName = name;
            }
            else if (next.index == 2) {
                next.stepName = "2nd";
            }
            else if (next.index == 3) {
                next.stepName = "3rd";
            }
            else {
                next.stepName = next.index + "th";
            }

            if (getContext().getSequenceGenerator().isStepByStepMode()) {
                getContext().getSequenceGenerator().goStep(this);
            }
        }
        return next;
    }
}
